//
//  LOLWelcomeViewController.m
//  LOLer
//
//  Created by kaijie on 16/3/28.
//  Copyright © 2016年 kaijie. All rights reserved.
//

#import "LOLWelcomeViewController.h"
#import "LOLMainTabBarController.h"
#import "AppDelegate.h"

@interface LOLWelcomeViewController ()<UIScrollViewDelegate>
S_property(UIPageControl, pageControl)
S_property(UIButton, ButtonOfWelcome)
S_property(UIScrollView, scrollViews)
@end

@implementation LOLWelcomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor=[UIColor grayColor];
    [self.view addSubview:self.scrollViews];
    [self.view addSubview:self.pageControl];
    [self.scrollViews addSubview:self.ButtonOfWelcome];
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma make
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGPoint offset = scrollView.contentOffset;
    if (offset.x<=0) {
        offset.x=0;
        scrollView.contentOffset=offset;
    }
    NSInteger index=round(offset.x/scrollView.frame.size.width);
    self.pageControl.currentPage=index;
    _pageControl.pageIndicatorTintColor=[UIColor blackColor];
    
}
-(UIScrollView *)scrollViews{
    if (!_scrollViews) {
        _scrollViews=[UIScrollView new];
        _scrollViews=[[UIScrollView alloc]initWithFrame:self.view.frame];
//    for (int i =0; i<self.imageArray.count; i++) {
//        UIImage * image=[UIImage imageNamed:self.imageArray[i]];
//        UIImageView*imageView=[[UIImageView alloc]initWithImage:image];
//        CGRect frame=CGRectZero;
//        frame.origin.x=i*_scrollViews.frame.size.width;
//        frame.size=_scrollViews.frame.size;
//        imageView.frame=frame;
//        [_scrollViews addSubview:imageView];
//    }
        
        UIImageView*imageview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, _scrollViews.frame.size.width*5, _scrollViews.frame.size.height)];
        imageview.image=[UIImage imageNamed:@"wlcome4.jpg"];
        [_scrollViews addSubview:imageview];
        CGSize size=CGSizeMake(_scrollViews.frame.size.width*self.imageArray.count, _scrollViews.frame.size.height);
        _scrollViews.contentSize=size;
        _scrollViews.showsVerticalScrollIndicator=NO;
        _scrollViews.showsHorizontalScrollIndicator=NO;
        _scrollViews.pagingEnabled=YES;
        _scrollViews.delegate=self;
    }return _scrollViews;

    
}
-(NSArray *)imageArray{
    if (!_imageArray) {
        _imageArray=@[@"subscribe_match_subscribed_bg",@"talent_simulator_defense_bg",@"talent_simulator_offense_bg",@"talent_simulator_utility_bg",@"asd"];
    }
    return _imageArray;
}
-(UIPageControl *)pageControl{
    if (!_pageControl) {
        _pageControl=[UIPageControl new];
        _pageControl.frame=CGRectMake(0, self.view.frame.size.height-40, self.view.frame.size.width, 20);
        _pageControl.numberOfPages=self.imageArray.count;
        _pageControl.pageIndicatorTintColor=[UIColor blackColor];
        _pageControl.userInteractionEnabled=NO;

    }return _pageControl;
}
-(UIButton *)ButtonOfWelcome{
    if (!_ButtonOfWelcome) {
        _ButtonOfWelcome=[UIButton new];
        CGRect frame=self.view.frame;
        frame.origin.x=self.scrollViews.frame.size.width*(self.imageArray.count-1);
        _ButtonOfWelcome.frame=frame;
        [_ButtonOfWelcome addTarget:self action:@selector(Come) forControlEvents:UIControlEventTouchUpInside];
    }return _ButtonOfWelcome;
}
-(void)Come{
        LOLMainTabBarController*view=[LOLMainTabBarController new];
//    [self presentViewController:view animated:YES completion:nil];
    
    AppDelegate*app2=[UIApplication sharedApplication].delegate;

    app2.window.rootViewController=view;
    
    
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
